package com.hong.utils.executors;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @Auther: Administrator
 * @Date: 2018/7/26 18:49
 * @Description:
 */
public class ThreadPoolExecutorLongTime {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = new ThreadPoolExecutor(10,20,30,TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10), r -> {
            Thread t = new Thread(r);
            t.setDaemon(true);
            return t;
        },new ThreadPoolExecutor.AbortPolicy());

        IntStream.range(0,10).boxed().forEach(i->{
            executorService.submit(()->{
                while (true){

                }
            });
        });

        //seq
        executorService.shutdownNow();
        executorService.awaitTermination(5,TimeUnit.SECONDS);
        System.out.println("===============start the sequence working==========");
    }
}
